import {
  Body,
  Controller,
  Get,
  Param,
  Post,
  Put,
  Delete,
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';

//新建博客或更新博客入参类
class CreatePostDto {
  id?: number;
  title: string;
  content: string;
}

@Controller('posts')
@ApiTags('博客')
export class PostsController {
  @Get()
  @ApiOperation({ summary: '获取博客列表' })
  getPosts() {
    return {
      code: '200',
      message: 'success',
      data: [
        {
          id: 1,
          title: 'Post 1',
          content: 'This is the content of post 1',
        },
      ],
    };
  }

  @Post()
  @ApiOperation({ summary: '创建博客' })
  createPost(@Body() body: CreatePostDto) {
    return {
      code: '200',
      message: 'success',
    };
  }

  @Get(':id')
  @ApiOperation({ summary: '获取博客详情' })
  getDetails(@Param('id') id: number) {
    return {
      code: '200',
      message: 'success',
      data: [
        {
          id: 1,
          title: 'Post 1',
          content: 'This is the content of post 1',
        },
      ],
    };
  }

  @Put()
  @ApiOperation({ summary: '更新博客' })
  updatePost(@Body() body: CreatePostDto) {
    return {
      code: '200',
      message: 'success',
      body,
    };
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除博客' })
  deletePost(@Param('id') id: number) {
    return {
      code: '200',
      message: 'success',
    };
  }
}
